/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package SysAguas.Testes;

import SysAguas.dao.DAOGenerico;
import SysAguas.modelo.Cartao;
import SysAguas.modelo.Hospede;
import SysAguas.modelo.Quarto;
import SysAguas.modelo.Reserva;
import SysAguas.modelo.StatusReserva;
import java.util.Calendar;
import java.util.Date;

/**
 *
 * @author Heitor
 */
public class ReservaTeste {

    public static void main(String[] args) {

        DAOGenerico dao = new DAOGenerico();

        /*
        Reserva r = new Reserva();
        r.setDesconto(20);
        r.setDataModificacao(Calendar.getInstance().getTime());
        r.setDataChegada(new Date(110, 05, 26));
        r.setDataSaida(new Date(110, 06, 05));
        r.setStatusReserva(StatusReserva.RESERVADA);

        //cadastrando a reserva********************
        dao.cadastrar(r);
        /**/

///*
//recuperando uma reserva *****************
        Reserva rer = dao.consultarPorChave(Reserva.class, 3);
        System.out.println(rer.getStatusReserva());



// atualizando uma reserva *******************

        Quarto q1 = dao.consultarPorChave(Quarto.class, 2);
        Quarto q2 = dao.consultarPorChave(Quarto.class, 3);

        Hospede hosp = dao.consultarPorChave(Hospede.class, 20);

        Cartao cartao = dao.consultarPorChave(Cartao.class, 2);
/*
        dao.abreConexao();
        dao.getEntityManeger().getTransaction().begin();

        rer.setQuarto(q1);
        q1.setReservaQ(rer);
        rer.setQuarto(q2);
        q2.setReservaQ(rer);

        rer.setHospedeR(hosp);
        hosp.addReserva(rer);

        rer.setPagamentoR(cartao);
        cartao.setReservaP(rer);


        dao.getEntityManeger().merge(cartao);
        dao.getEntityManeger().merge(q1);
        dao.getEntityManeger().merge(q2);
        dao.getEntityManeger().merge(hosp);
        dao.getEntityManeger().flush();
        dao.getEntityManeger().getTransaction().commit();

        dao.fechaConexao();
/**/


///*
//removendo a reserva *************************
        dao.abreConexao();
        dao.getEntityManeger().getTransaction().begin();

        rer.removeQuarto(q1,q2);
        q1.removeReserva(rer);
        q2.removeReserva(rer);
        
        dao.getEntityManeger().merge(q1);
        dao.getEntityManeger().merge(q2);

        dao.remover(rer);
/**/
    }
}
